home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Kant Generator Pro 1.0.1 / source / kode new / kant main window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  5.7 KB  |  251 lines  |  [TEXT/MMCC]

  1. #include "kant main window.h"
  2. #include "kant load-save.h"
  3. #include "environment.h"
  4. #include "util.h"
  5. #include "menus.h"
  6. #include "main.h"
  7. #include "dialogs.h"
  8. #include "text twiddling.h"
  9. #include "generic window handlers.h"
  10. #include "window layer.h"
  11. #include "program globals.h"
  12.  
  13. #define kGrowBoxSize        15
  14.  
  15. static    void PutDataIntoTEFields(WindowPtr theWindow);
  16.  
  17. static    short            gOldForegroundTime;        /* stored foreground wait time */
  18. static    CursHandle        gMyIBeamHandle;
  19. static    Boolean            gSetupDone=FALSE;
  20. static    Boolean            gIsActive=FALSE;
  21.  
  22. void SetupTheMainWindow(WindowPtr theWindow)
  23. {
  24.     unsigned char    *titleStr="\puntitled";
  25.     Point            topLeft;
  26.     FSSpec            fs;
  27.     
  28.     SetWindowHeight(theWindow, qd.screenBits.bounds.bottom-qd.screenBits.bounds.top-LMGetMBarHeight()-28);
  29.     SetWindowWidth(theWindow, qd.screenBits.bounds.right-qd.screenBits.bounds.left-70);
  30.     SetWindowType(theWindow, zoomDocProc);
  31.     topLeft.v=qd.screenBits.bounds.top+LMGetMBarHeight()+20;
  32.     topLeft.h=qd.screenBits.bounds.left+10;
  33.     SetWindowTopLeft(theWindow, topLeft);
  34.     SetWindowHasCloseBox(theWindow, TRUE);
  35.     SetWindowMaxDepth(theWindow, 1);
  36.     SetWindowDepth(theWindow, 1);
  37.     SetWindowIsFloat(theWindow, FALSE);
  38.     SetWindowTitle(theWindow, titleStr);
  39.     SetWindowAutoCenter(theWindow, FALSE);
  40.     fs.name[0]=0x00;
  41.     fs.vRefNum=0;
  42.     fs.parID=0;
  43.     SetWindowFS(theWindow, fs);
  44.     SetWindowIsModified(theWindow, FALSE);
  45.     if (gSetupDone)
  46.         return;
  47.     
  48.     gSetupDone=TRUE;
  49.     gMyIBeamHandle=GetCursor(iBeamCursor);
  50. }
  51.  
  52. void ShutDownTheMainWindow(void)
  53. {
  54.     if (gMyIBeamHandle!=0L)
  55.         ReleaseResource((Handle)gMyIBeamHandle);
  56. }
  57.  
  58. void OpenTheMainWindow(WindowPtr theWindow)
  59. {
  60.     TEHandle        hTE;
  61.     FontInfo        theFontInfo;
  62.     Rect            vScrollBarRect, hScrollBarRect;
  63.     Rect            destRect, viewRect;
  64.     
  65.     hTE=GetWindowTE(theWindow);
  66.     if (hTE==0L)
  67.     {
  68.         SetRect(&vScrollBarRect, GetWindowWidth(theWindow)-kGrowBoxSize, -1,
  69.             GetWindowWidth(theWindow)+1, GetWindowHeight(theWindow)+1-kGrowBoxSize);
  70.         SetRect(&hScrollBarRect, -1, GetWindowHeight(theWindow)-kGrowBoxSize,
  71.             GetWindowWidth(theWindow)-kGrowBoxSize+1, GetWindowHeight(theWindow)+1);
  72.         SetWindowVScrollBar(theWindow,
  73.             NewControl(theWindow, &vScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
  74.         SetWindowHScrollBar(theWindow,
  75.             NewControl(theWindow, &hScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
  76.         
  77.         GetTERect(theWindow, &destRect, TRUE);
  78.         viewRect=destRect;
  79.         hTE=TENew(&destRect, &viewRect);
  80.         SetWindowTE(theWindow, hTE);
  81.         TextFont((**hTE).txFont=monaco);
  82.         TextSize((**hTE).txSize=9);
  83.         TextFace((**hTE).txFace=0);
  84.         GetFontInfo(&theFontInfo);
  85.         (**hTE).fontAscent=theFontInfo.ascent;
  86.         (**hTE).lineHeight=theFontInfo.ascent+theFontInfo.descent+theFontInfo.leading;
  87.         AdjustViewRect(hTE);
  88.         TEAutoView(TRUE, hTE);
  89.         TESetClickLoop((ProcPtr)MyClikLoop, hTE);
  90.         PutDataIntoTEFields(theWindow);
  91.     }
  92.     
  93.     gIsActive=TRUE;
  94.     AdjustVScrollBar(GetWindowVScrollBar(theWindow), hTE);
  95.     AdjustMenus();
  96. }
  97.  
  98. void IdleInMainWindow(WindowPtr theWindow, Point mouseLoc)
  99. {
  100.     TEHandle        hTE;
  101.     
  102.     if (gInProgress)
  103.         return;
  104.     
  105.     hTE=GetWindowTE(theWindow);
  106.     TEIdle(hTE);
  107.     
  108.     if (PtInRect(mouseLoc, &((**hTE).viewRect)))
  109.     {
  110.         if (!gCustomCursor)
  111.         {
  112.             SetCursor(*gMyIBeamHandle);
  113.             gCustomCursor=TRUE;
  114.         }
  115.     }
  116.     else
  117.     {
  118.         gCustomCursor=FALSE;
  119.     }
  120. }
  121.  
  122. void KeyPressedInMainWindow(WindowPtr theWindow, unsigned char theChar)
  123. {
  124.     TEHandle        hTE;
  125.     ControlHandle    vScrollBar;
  126.     
  127.     hTE=GetWindowTE(theWindow);
  128.     vScrollBar=GetWindowVScrollBar(theWindow);
  129.     
  130.     switch (theChar)
  131.     {
  132.         case 0x09:
  133.             TESetSelect(0, 32767, hTE);
  134.             break;
  135.         default:
  136.             TEKey(theChar, hTE);
  137.             SetWindowIsModified(theWindow, TRUE);
  138.             break;
  139.     }
  140.     
  141.     AdjustVScrollBar(vScrollBar, hTE);
  142. }
  143.  
  144. void DisposeTheMainWindow(WindowPtr theWindow)
  145. {
  146.     TEHandle        hTE;
  147.     
  148.     hTE=GetWindowTE(theWindow);
  149.     if (hTE!=0L)
  150.     {
  151.         TEDispose(hTE);
  152.         SetWindowTE(theWindow, 0L);
  153.     }
  154. }
  155.  
  156. Boolean CloseTheMainWindow(WindowPtr theWindow)
  157. {
  158.     ModalFilterUPP    procFilter = NewModalFilterProc(ThreeButtonFilter);
  159.     short            result;
  160.     
  161.     if (WindowIsModifiedQQ(theWindow))
  162.     {
  163.         SetCursor(&qd.arrow);
  164.         PositionDialog('ALRT', saveAlert);
  165.         ParamText(GetWindowTitle(theWindow), "\p", "\p", "\p");
  166.         result=Alert(saveAlert, procFilter);
  167.         DisposeRoutineDescriptor(procFilter);
  168.         switch (result)
  169.         {
  170.             case 1:    /* save */
  171.                 LoadSaveDispatch(FALSE, TRUE);
  172.                 if (WindowIsModifiedQQ(theWindow))    /* save didn't work for some reason */
  173.                     return FALSE;
  174.                 break;
  175.             case 2:     /* cancel */
  176.                 return FALSE;
  177.                 break;
  178.             case 3:    /* don't save */
  179.                 break;
  180.         }
  181.     }
  182.     
  183.     gCustomCursor=FALSE;
  184.     
  185.     return TRUE;
  186. }
  187.  
  188. void ActivateTheMainWindow(WindowPtr theWindow)
  189. {
  190.     gOldForegroundTime=gForegroundWaitTime;
  191.     gForegroundWaitTime=0;
  192.     gIsActive=TRUE;
  193. }
  194.  
  195. void DeactivateTheMainWindow(WindowPtr theWindow)
  196. {
  197.     gForegroundWaitTime=gOldForegroundTime;
  198.     gIsActive=FALSE;
  199. }
  200.  
  201. void CopybitsTheMainWindow(WindowPtr theWindow, WindowPtr offscreenWindow)
  202. {
  203.     GenericCopybits(theWindow, offscreenWindow, gIsActive);
  204. }
  205.  
  206. void PasteInMainWindow(WindowPtr theWindow)
  207. {
  208.     TEHandle        hTE;
  209.     ControlHandle    vScrollBar;
  210.     Handle            scrapHandle;
  211.     long            offset;
  212.     unsigned long    scrapLength;
  213.     unsigned char    *theSource="\pMBDF-A";
  214.     unsigned char    *theTarget="\pProgramming is not a crime.";
  215.     
  216.     hTE=GetWindowTE(theWindow);
  217.     vScrollBar=GetWindowVScrollBar(theWindow);
  218.     
  219.     scrapHandle=NewHandle(0L);
  220.     if (GetScrap(scrapHandle, 'TEXT', &offset)!=noTypeErr)
  221.     {
  222.         scrapLength=GetHandleSize(scrapHandle);
  223.         if (scrapLength==theSource[0])
  224.         {
  225.             HLock(scrapHandle);
  226.             if (Mymemcompare((Ptr)*scrapHandle, (Ptr)&theSource[1], theSource[0]))
  227.             {
  228.                 ZeroScrap();
  229.                 PutScrap(theTarget[0], 'TEXT', (char*)&theTarget[1]);
  230.             }
  231.         }
  232.         
  233.         TEFromScrap();
  234.         TEPaste(hTE);
  235.         TESelView(hTE);
  236.         if (vScrollBar!=0L)
  237.             AdjustVScrollBar(vScrollBar, hTE);
  238.     }
  239.     DisposeHandle(scrapHandle);
  240. }
  241.  
  242. static    void PutDataIntoTEFields(WindowPtr theWindow)
  243. {
  244.     TEHandle            hTE;
  245.     
  246.     hTE=GetWindowTE(theWindow);
  247.     TESetSelect(0, 0, hTE);
  248.     TEKey(0x00, hTE);
  249.     TEKey(0x08, hTE);
  250. }
  251.